﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;

namespace YasharEl.Infrastructure.ResourcesManagement.Managers
{
    /// <summary>
    /// Resource file name helper class
    /// </summary>
    public static class ResourceFileName
    {
        #region Public Methods

        /// <summary>
        /// Builds the specified resource file name.
        /// </summary>
        /// <param name="pathName">The path to the resource file.</param>
        /// <param name="baseName">resource file base name.</param>
        /// <param name="cultureInfo">The resource culture.</param>
        /// <param name="extension">The resource file extension.</param>
        /// <returns></returns>
        public static string Build(string pathName, string baseName, CultureInfo cultureInfo, string extension)
        {
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(pathName), "pathName could not be null or empty.");
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(baseName), "baseName could not be null or empty.");
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(extension), "extension could not be null or empty.");

            CultureInfo culture;
            string fileName;


            if (cultureInfo == null)
                culture = CultureInfo.InvariantCulture;
            else
                culture = cultureInfo;

            fileName = baseName;
            if (culture.Equals(CultureInfo.InvariantCulture))
                fileName += extension;
            else
                fileName += "." + culture.Name + extension;

            return Path.Combine(pathName, fileName);
        }

        #endregion
    }
}
